package com.example.travelservlet.userLabel.service;

import com.example.travelservlet.entity.UserLabel;
import com.example.travelservlet.userLabel.repository.UserLabelRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 30697
 */
@Service
public class UserLabelServiceImpl implements UserLabelService{
    @Autowired
    private UserLabelRepository userLabelRepository;

    @Override
    public List<UserLabel> createUserLabels(List<UserLabel> userLabels) {
        return userLabelRepository.saveAll(userLabels);
    }

    @Override
    public List<String> findLabelIdsByUserId(String userId) {
        List<UserLabel> userLabels = userLabelRepository.findAllByUserId(userId);
        List<String> labelIds = new ArrayList<>();
        for (UserLabel userLabel : userLabels) {
            labelIds.add(userLabel.getLabelId());
        }
        return labelIds;
    }

    @Override
    public List<UserLabel> findAll() {
        List<UserLabel> all = userLabelRepository.findAll();
        return all;
    }
}
